#include "ST_RANKING.h"
#include "Game/dConfig.h"
#include "Game/Game.h"
#include "GameRes/DataRecord.h"
#include "Tools/Image.h"
namespace LTGame
{
	ST_RANKING::ST_RANKING(GST_FLAG flag)
		: GameState(flag)
	{
		imgRanking_bg = CCSprite::spriteWithFile("gui_pic/ranking.jpg");
		imgRanking_bg->setPosition(ccp(S_WIDTH_HALF, S_HEIGHT_HALF));
		imgRanking_bg->retain();
		DataRecord::getDataRecord();
	}
	ST_RANKING::~ST_RANKING()
	{
		CC_SAFE_DELETE(imgRanking_bg);
	}
	bool ST_RANKING::logic(void)
	{
		imgRanking_bg->visit();
		return true;
	}
	void ST_RANKING::paint(void)
	{
		for (unsigned i = 0;i < 10;i++)
		{
			Image::drawImageNum(CCGame->rankingNum,CCGame->soreRanking[9-i],(float)S_WIDTH_HALF,(float)S_WIDTH_HALF-45+i*(46.5),ANCHOR_LT);
		}
	}
	bool ST_RANKING::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
	{
		return true;
	}
	void ST_RANKING::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent)
	{
		CCPoint point = pTouch->locationInView( pTouch->view() );

 		if (CCGame->m_uiData->isPointerInBlock(point.x,point.y,Form_SelPlane,B_Form_Block_3))
 		{
			memset(CCGame->soreRanking,0,10*sizeof(int));		
 			CCGame->setCurLevelId(CCGame->levelIndex);
			DataRecord::setDataRecord();
 		}
 		else if (CCGame->m_uiData->isPointerInBlock(point.x,point.y,Form_SelPlane,B_Form_Block_2))
		{
			CCGame->SetState(CCGame->getPreStateFlag());
		}
	}

}